// Default empty project template
#include "HelloWord.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Label>
using namespace bb::cascades;

HelloWord::HelloWord(bb::cascades::Application *app) :
		QObject(app) {
	// create scene document from main.qml asset
	// set parent to created document to ensure it exists for the whole application lifetime
	QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

	qml->setContextProperty("_app", this);

	// create root object for the UI
	root = qml->createRootObject<AbstractPane>();
	// set created root object as a scene
	app->setScene(root);

}

void HelloWord::changerText() {
	Label * myLabel = root->findChild<Label*>("myLabel");
	myLabel->setText("Cộng Hòa Xã Hội Chủ Nghĩa");
	logP("InC++");
}

void HelloWord::processFromQML() {
	logP("InC++");
	QVariant returnValue;
	QMetaObject::invokeMethod(root, "fromQML",
			Q_RETURN_ARG(QVariant,returnValue));
		}
void HelloWord::logFromQML(QString message) {
	logP(message.toUtf8().constData());
}
void HelloWord::logP(const char* msg) {
	fprintf(stdout,"%s\n",msg);
	fflush(stdout);
}
